package com.amir.common.utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.amir.common.R;
import com.wang.avi.AVLoadingIndicatorView;

import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;

public class MyProgressLoading extends Dialog {

    private AVLoadingIndicatorView iv_loading;
    private Context mContext;

    public MyProgressLoading(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        this.mContext = context;


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_press);
        iv_loading = findViewById(R.id.iv_loading);
        ImageView loadingImage = findViewById(R.id.loadingImage);
        AnimationDrawable animationDrawable = (AnimationDrawable) loadingImage.getBackground();
        animationDrawable.start();
        loadingImage.setBackground(null);
        loadingImage.setImageDrawable(animationDrawable);
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//        lp.x = 100; // 新位置X坐标
//        lp.y = 100; // 新位置Y坐标
        // lp.width = 3000; // 宽度
        //   lp.height = 6600; // 高度
        //  lp.alpha = 1.0f; // 透明度
        // lp.dimAmount = 0.6f; // 透明度
        //   lp.flags=WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        lp.gravity = Gravity.CENTER;
        dialogWindow.setAttributes(lp);

        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
//        //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
        //       getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//        //一定要在setContentView之后调用，否则无效
        //   getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);


////设置dialog沉浸式效果
//        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
//            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        } else {
//            getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//            getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
//        }

    }

//
//        DraweeController draweeController =
//                Fresco.newDraweeControllerBuilder()
//
//                        .setAutoPlayAnimations(true) // 设置加载图片完成后是否直接进行播放
//                        .build();
//
//        iv_loading.setController(draweeController);

}

